<?php
$articles = $this->object;
$articlesModel = new Admin_Model_Articles();
?>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span3"><?php echo $this->partial('choix/menu.phtml') ?></div>
        <div class="span9">
            <div class="wrap">
                <div id="main-content">
                    <form class="form-horizontal" method="post" action="<?php echo $this->baseUrl('admin/articles/save') ?>">
                        <h3>Edition</h3>
                        <ul class="nav nav-tabs" id="edit-form-tab">
                    		<li class="frm1 active"><a href="#frm1">Généralités</a></li>
                    		<li class="frm2"><a href="#frm2">Offrant n°</a></li>
                    	</ul>
                        <input type="hidden" name="num_vente" value="<?php echo $this->numVente ?>" />
                        <input type="hidden" name="id" value="<?php echo $this->request()->getParam('id') ?>" />
                        <div class="tab-content">
                            <div class="tab-pane active" id="frm1">
                                <div class="control-group">
                                    <label class="control-label" for="droit_suite">Droit de suite ? </label>
                                    <div class="controls">
                                        <input type="checkbox" value="1" name="data[droit_suite]" id="droit_suite" <?php if ($articles->getDroitSuite()) : ?>checked<?php endif ?> />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">N&deg; : </label>
                                    <div class="controls">
                                        <?php echo $articles->getNumArticle() ?>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="f_clients_deposant">D&eacute;posant : </label>
                                    <div class="controls">
                                        <select name="data[f_clients_deposant]" id="f_clients_deposant">
                                            <?php foreach ($articlesModel->getClients() as $client) : ?>
                                            <option value="<?php echo $client['p_clients'] ?>" <?php if ($articles->getFClientsDeposant() == $client['p_clients']) : ?>selected<?php endif ?>><?php echo $client['nom'] ?> <?php echo $client['prenom'] ?></option>
                                            <?php endforeach ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="adjuge">Adjug&eacute; : </label>
                                    <div class="controls">
                                        <input name="data[adjuge]" id="adjuge" type="text" size="10" value="<?php echo $articles->getAdjuge() ?>" placeholder="Adjug&eacute;" />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="acheteur">Acheteur : </label>
                                    <div class="controls">
                                        <?php if ($this->request()->getParam('id')) : ?>
                                            <?php $acheteur = $articlesModel->getAcheteur($articles->getFClientsAcheteur(), $this->numVente) ?>
                                            <input name="=acheteur" id="acheteur" type="text" size="10" value="<?php echo (int) $acheteur['num_client'] ?>" placeholder="Acheteur" />
                                            <?php echo $acheteur['nom'] ?> <?php echo $acheteur['prenom'] ?>
                                        <?php else : ?>
                                            -------
                                        <?php endif ?>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="commission">Comm sp&eacute;ciale : </label>
                                    <div class="controls">
                                        <input name="data[commission]" id="commission" type="text" size="10" value="<?php echo $articles->getCommission() != '99' ? $articles->getCommission() : '' ?>" placeholder="Comm sp&eacute;ciale" />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="f_series">S&eacute;rie : </label>
                                    <div class="controls">
                                        <select name="data[f_series]" id="f_series">
                                            <?php foreach ($articlesModel->getSeries() as $serie) : ?>
                                            <option value="<?php echo $serie['p_series'] ?>" <?php if ($articles->getFSeries() == $serie['p_series']) : ?>selected<?php endif ?>><?php echo $serie['titre'] ?></option>
                                            <?php endforeach ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="numero">N&deg; identifiant : </label>
                                    <div class="controls">
                                        <input name="data[numero]" id="numero" type="text" value="<?php echo $articles->getNumero() ?>" placeholder="N&deg; identifiant" />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sous">Sous-n&deg; : </label>
                                    <div class="controls">
                                        <input name="data[sous]" id="sous" type="text" value="<?php echo $articles->getSous() ?>" placeholder="Sous-n&deg;" />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="desc_courte">Description courte : </label>
                                    <div class="controls">
                                        <textarea name="data[desc_courte]" id="desc_courte" style="width: 95%"><?php echo $articles->getDescCourte() ?></textarea>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="desc_longue">Description longue : </label>
                                    <div class="controls">
                                        <textarea name="data[desc_longue]" id="desc_longue" style="width: 95%"><?php echo $articles->getDescLongue() ?></textarea>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="f_categories">Cat&eacute;gorie : </label>
                                    <div class="controls">
                                        <select name="data[f_categories]" id="f_categories">
                                            <?php foreach ($articlesModel->getCategories($this->numVente) as $category) : ?>
                                            <option value="<?php echo $category['p_categories'] ?>" <?php if ($articles->getFCategories() == $category['p_categories']) : ?>selected<?php endif ?>><?php echo $category['nom'] ?></option>
                                            <?php endforeach ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="estimation">Estimation : </label>
                                    <div class="controls">
                                        <input name="data[estimation]" id="estimation" type="text" value="<?php echo $articles->getEstimation() ?>" placeholder="Estimation" />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" id="reserve">R&eacute;serve : </label>
                                    <div class="controls">
                                        <input name="data[reserve]" id="reserve" type="text" value="<?php echo $articles->getReserve() ?>" placeholder="R&eacute;serve" />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="caisse">Caisse : </label>
                                    <div class="controls">
                                        <input name="data[caisse]" id="caisse" type="text" value="<?php echo $articles->getCaisse() != 0 ? $articles->getCaisse() : '' ?>" placeholder="Caisse" />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="ventes">Déplacer vers la vente : </label>
                                    <div class="controls">
                                        <select name="data[f_ventes]" id="ventes">
                                            <?php $venteSelected = $articles->getFVentes() ? $articles->getFVentes() : $this->numVente ?>
                                            <?php foreach ($articlesModel->getVentes() as $vente) : ?>
                                            <option value="<?php echo $vente['p_ventes'] ?>" <?php if ($venteSelected == $vente['p_ventes']) : ?>selected<?php endif ?>>
                                                <?php echo date('d/m/Y', strtotime($vente['dtvente'])) ?> - <?php echo $vente['titre'] ?>
                                            </option>
                                            <?php endforeach ?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="tab-pane" id="frm2">
                                <div class="control-group">
                                    <table>
                                        <tr>
                                          	<td class="td-head">Offrant n°</td>
                                            <td class="td-head">Offre</td>
                                            <td class="td-head">Tél 1</td>
                                            <td class="td-head">Tél 2</td>
                                        </tr>
                                        <?php
                                            $clients = $articlesModel->getClientsOffrant($this->request()->getParam('num_vente'));
                                            $limits = $this->request()->getParam('id') ? 10 : 5;
                                            for($i = 1; $i < $limits; $i++) :
                                                $offset = $i - 1;
                                                if ($this->request()->getParam('id')) {
                                                    $offrant = $articlesModel->getArticleOffrant($articles->getPArticles(), $offset);
                                                } else {
                                                    $offrant =array('f_clients' => 0, 'offre' => '', 'tel_spec1' => '', 'tel_spec2' => '');
                                                }
                                                $larow = $offrant['f_clients'] ? $offrant['f_clients'] : 0;
                                        ?>
                                        <tr>
                                            <td>
                                                <select name="offrant[<?php echo $i ?>][f_clients]">
                                                    <option value="0">-----------</option>
                                                    <?php foreach ($clients as $client) : ?>
                                                    <option value="<?php echo $client['p_clients'] ?>"<?php if ($client['p_clients'] == $larow) : ?> selected<?php endif ?>>
                                                        <?php echo $client['p_clients'] != 0 ? $client['p_clients'] . ' - ' : '' ?>
                                                        <?php echo $client['nom'] ?>
                                                        <?php echo $client['prenom'] ?>
                                                    </option>
                                                    <?php endforeach ?>
                                                </select>
                                            </td>
                                            <td><input name="offrant[<?php echo $i ?>][offre]" type="text" size="20" value="<?php echo $offrant['offre'] ?>" /></td>
                                            <td><input name="offrant[<?php echo $i ?>][tel_spec1]" type="text" size="20" value="<?php echo $offrant['tel_spec1'] ? $offrant['tel_spec1'] : '' ?>" /></td>
                                            <td><input name="offrant[<?php echo $i ?>][tel_spec2]" type="text" size="20" value="<?php echo $offrant['tel_spec2'] ? $offrant['tel_spec2'] : '' ?>" /></td>
                                        </tr>
                                        <?php endfor ?>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div align="center">
                            <input class="btn btn-primary" type="submit" value="Sauver" name="submit" />
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>